package com.lk.mall.controller.mall;


import com.lk.mall.model.entity.GoodsInfo;
import com.lk.mall.model.vo.GoodsDetailVo;
import com.lk.mall.service.IGoodsInfoService;
import com.lk.mall.util.BeanUtil;
import com.lk.mall.util.R;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lak
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/api/v1/goods")
@Api(tags = "3.新蜂商城首页接口")
public class GoodsInfoController {
    @Autowired
    private IGoodsInfoService goodsInfoService;

    //商品详情
    @GetMapping("detail/{goodsId}")
    public R getGoodsDetail(@PathVariable Long goodsId) {
        GoodsDetailVo goodsDetailVo = new GoodsDetailVo();
        GoodsInfo goodsInfo = goodsInfoService.getGoodInfoById(goodsId);
        String[] goodCarouselList=goodsInfo.getGoodsCarousel().split(",");

        BeanUtils.copyProperties(goodsInfo,goodsDetailVo);
        goodsDetailVo.setGoodsCarouselList(goodCarouselList);
        return new R<GoodsDetailVo>().ok(goodsDetailVo);
    }
}

